$(function () {
    let markId = getUrlString('markid');
    let type = getUrlString('type');
    let page = -1,time = '3',mainseries = '',maker = '',totalSize;

    let mRefresh = new MiniRefresh({
        container: '#mrefresh', //这里是插件的容器ID
        down: {
            isAuto: false,
            callback: function () {
                // 下拉后的回调事件 ，你可以在这里执行你的后台请求数据函数，达到刷新数据的作用
                $('#usedList').empty();
                totalSize = 0;
                page = -1;
                mRefresh.endDownLoading();
            }
        }
        ,
        up: {
            isAuto: true,
            callback: function () {
                // 向上拉后的回调事件
                page += 1;
                getListData(page,time,mainseries,maker);
            }
        }
    });

    function getListData (page,time,mainseries,maker){
        let data = {
            'page':page,
            'markid':markId,
            'type':type,
            'time':time,
            'mainseries':mainseries,
            'maker':maker,
        };
        getData('post','/niu/apiv4/niu_cate_allsearch.php',data,function (data) {
            console.log(data);
            let append = '';
            $(data.info).each(function () {
                append += '<li>' +
                    ' <input type="hidden" value="'+this.id+'"> '+
                    '                    <div class="left">' +
                    '                        <img src="'+this.pics+'" alt="">' +
                    '                    </div>' +
                    '                    <div class="right">' +
                    '                        <div class="name">'+this.name+'</div>' +
                    '                        <div class="lable">' +
                    '                            <span>'+this.typeName+'</span>' +
                    '                            <span>'+this.maker+'</span>' +
                    '                            <span>'+this.mainseries+'</span>' +
                    '                        </div>' +
                    '                    </div>' +
                    '                </li>'
            });
            $('#usedList').append(append);

            totalSize = totalSize + 10;
            if (totalSize > data.datacount){
                mRefresh.endUpLoading(true);
            } else{
                mRefresh.resetUpLoading(true);
                mRefresh.endUpLoading(false);
            }
        })
    }

    $("#usedList li").live("click", function(){
        let id = $(this).find('input').val();
        window.location.href = 'dancool://web='+urlView+'productData/dataDetail.html?id='+id;
    });

    //获取分类
    let IPVal = ["全部"];
    let nameVal = ["全部"];
    function getType (){
        let data = {
            'markid':markId
        };
        getData('post','/niu/apiv4/niu_makersworks.php',data,function (data) {
            console.log(data);
            $(data.makerinfo).each(function () {
                IPVal.push(this.name)
            });
            IPVal.push('其他');
            $(data.maininfo).each(function () {
                nameVal.push(this.name)
            });
            nameVal.push('其他')
        })
    }

    getType();







    $("#year").picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-right close-picker">确定</button>\
          <h1 class="title">请选择年份</h1>\
        </header>',
        cols: [
            {
                textAlign: 'center',
                values: ['全部','2020', '2019', '2018', '2017', '2016', '2015', '2014', '2013', '2012', '2011', '2010', '2010年前']
            }
        ],
        onClose:function () {
            time = $('#year').val()+'00';
            if (time === '全部00'){
                time = '3'
            }else if (time === '2010年前00') {
                time = 'before'
            }
            $('#usedList').empty();
            totalSize = 0;
            page = -1;
            mRefresh.triggerDownLoading();
            // getListData(page,time,mainseries,maker);
        }
    });
    $("#IP").picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-right close-picker">确定</button>\
          <h1 class="title">请选择品牌</h1>\
        </header>',
        cols: [
            {
                textAlign: 'center',
                values: IPVal
            }
        ],
        onClose:function () {
            maker = $('#IP').val();
            if (maker === '全部'){
                maker = ''
            }else if (maker === '其他') {
                maker = 'other'
            }
            $('#usedList').empty();
            totalSize = 0;
            page = -1;
            mRefresh.triggerDownLoading();
            // getListData(page,time,mainseries,maker);

        }
    });
    $("#name").picker({
        toolbarTemplate: '<header class="bar bar-nav">\
          <button class="button button-link pull-right close-picker">确定</button>\
          <h1 class="title">请选择作品名</h1>\
        </header>',
        cols: [
            {
                textAlign: 'center',
                values: nameVal
            }
        ],
        onClose:function () {
            mainseries = $('#name').val();
            if (mainseries === '全部'){
                mainseries = ''
            }else if (mainseries === '其他') {
                mainseries = 'other'
            }
            $('#usedList').empty();
            totalSize = 0;
            page = -1;
            mRefresh.triggerDownLoading();
            // getListData(page,time,mainseries,maker);
        }
    });
});